<%@ Page Language="C#" MasterPageFile="~/FiledbookMaster.Master" AutoEventWireup="true" CodeBehind="Machines.aspx.cs" Inherits="Fieldbook.Testwebsite.User.Machines" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function ShowHideDiv(on, elemID)
        {
            var divElem = document.getElementById(elemID);
            if (on)
            {
                divElem.style.display = "block";
            }
            else 
            {
                divElem.style.display = "none";
            }
            return false;
        }
    </script>

    <a href="#" onclick="return ShowHideDiv(true, 'divAddMachineCategory')">Add machine category</a> |
    <a href="#" onclick="return ShowHideDiv(true, 'divAddMachine')">Add machine</a>
    <br />
    <br />
    <asp:Label ID="lblOperationStatus" runat="server" EnableViewState="false"/>
    <div id="divAddMachineCategory" style="display:none;">
        <table>
            <tr>
                <td>Description: </td>
                <td>
                    <asp:TextBox ID="txtMachineCategory" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:LinkButton id="linkAddCategory" runat="Server" OnCommand="linkAddCategory_Command" Text="Add"/>
                    <asp:LinkButton id="linkAddCategoryGlobal" runat="Server" 
                        OnCommand="linkAddCategory_Command" 
                        CommandArgument="global"
                        Text="Add global"/>
                    <a href="#" onclick="return ShowHideDiv(false, 'divAddMachineCategory')">Cancel</a>                        
                </td>
            </tr>
        </table>   
        <br/>
    </div>  
    <div id="divAddMachine" style="display:none;">
        <table>
            <tr>
                <td>Category: </td>
                <td>
                    <asp:DropDownList ID="ddlMachineCategory" runat="server"
                        DataSourceID="MachineCategoriesODS"
                        DataValueField="CategoryID"
                        DataTextField="Description"
                        />
                </td>
            </tr>
            <tr>
                <td>Registration: </td>
                <td>
                    <asp:TextBox ID="txtRegistration" runat="server" />
                </td>
            </tr>
            <tr>
                <td>Power: </td>
                <td>
                    <asp:TextBox ID="txtPower" runat="server" CssClass="txtnumber" />
                    <asp:DropDownList ID="ddlPowerMU" runat="server" 
                        DataSourceID="PowerMeasureUnitsODS"
                        DataValueField="MeasureUnitID"
                        DataTextField="Description">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>Capacity: </td>
                <td>
                    <asp:TextBox ID="txtVolumen" runat="server" CssClass="txtnumber" />
                    <asp:DropDownList ID="ddlVolumenMU" runat="server" 
                        DataSourceID="VolumenMeasureUnitsODS"
                        DataValueField="MeasureUnitID"
                        DataTextField="Description">
                    </asp:DropDownList>                    
                </td>
            </tr>
            <tr>
                <td>ProductionYear: </td>
                <td>
                    <asp:TextBox ID="txtProductionYear" runat="server" CssClass="txtnumber" />
                </td>
            </tr>                       
            <tr>
                <td>Description: </td>
                <td>
                    <asp:TextBox ID="txtDescription" runat="server" TextMode="multiLine" />
                </td>
            </tr>             
            <tr>
                <td colspan="2">
                    <asp:LinkButton id="linkAddMachine" runat="Server" OnCommand="linkAddMachine_Command" Text="Add"/>
                    <a href="#" onclick="return ShowHideDiv(false, 'divAddMachine')">Cancel</a>                        
                </td>
            </tr>            
        </table>    
    </div>  
    <asp:GridView ID="dgvMachineCategories" runat="server" AutoGenerateColumns="False" 
                  DataSourceID="MachineCategoriesODS" 
                  DataKeyNames="CategoryID"
                  OnSelectedIndexChanged="DgvMachineCategories_SelectedIndexChanged">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
        </Columns>
    </asp:GridView>
    <br />
    <asp:GridView ID="dgvMachines" runat="server" AutoGenerateColumns="false" OnRowDataBound="dgvMachines_RowDataBound">
    <Columns>
        <asp:BoundField DataField="Registration" HeaderText="Registration" SortExpression="Registration" />
        <asp:TemplateField>
            <HeaderTemplate>
                Power
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label ID="lblPower" runat="server" Text='<%#Eval("Power") %>' />
                <asp:Label ID="lblPowerMU" runat="server" Text='<%#Eval("PowerMU") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <HeaderTemplate>
                Capacity
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label ID="lblVolumen" runat="server" Text='<%#Eval("Volumen") %>' />
                <asp:Label ID="lblVolumenMU" runat="server" Text='<%#Eval("VolumenMU") %>' />
            </ItemTemplate>
        </asp:TemplateField>        
        <asp:BoundField DataField="ProductionYear" HeaderText="ProductionYear" SortExpression="ProductionYear"/>        
        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
    </Columns>
    </asp:GridView>
        
    <asp:ObjectDataSource ID="MachineCategoriesODS" runat="server" TypeName="Fieldbook.Business.MachineController" SelectMethod="LoadMachineCategories">
        <SelectParameters>
            <asp:SessionParameter Name="userID" Type="Int64" SessionField="userID" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="PowerMeasureUnitsODS" runat="server" TypeName="Fieldbook.Business.MeasureUnitController" SelectMethod="LoadMeasrueUnits">
        <SelectParameters>
            <asp:Parameter Name="category" Type="object" DefaultValue="3" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="VolumenMeasureUnitsODS" runat="server" TypeName="Fieldbook.Business.MeasureUnitController" SelectMethod="LoadMeasrueUnits">
        <SelectParameters>
            <asp:Parameter Name="category" Type="object" DefaultValue="2" />
        </SelectParameters>
    </asp:ObjectDataSource>
        
</asp:Content>
